<?php
/**********************************************************
** Lime Manager
** Thomas Knobloch & Clément Troesch
** Manager Rights Ajax View
***********************************************************/
?>

<?php session_start(); ?>
<?php include_once "../../model/ReferentialConnectionModel.php"; ?>
<?php include_once "../../Model/RightModel.php"; ?>
<?php include_once "../../Model/DatabaseModel.php"; ?>
<?php include_once "../../Model/UserModel.php"; ?>

<?php

//Modification
if(isset($_GET['change_right_userid']))
{	
	RightModel::editRight($_GET['change_right_userid'], $_GET['change_right_databaseid'], $_GET['change_right_value']);
}

?>

<div class="section_title"><h1> Droits </h1></div>
<div class="section_info">
	Gestion des droits.
</div>

<div class="article">

<table class="tableQueryCenter">
	<tr>
		<th>ID</th>
		<th>Login</th>
		<th>Rôle</th>
		<?php
		$nbrow = DatabaseModel::getDatabases($result);
		foreach ($result as $row) {
			echo "<th>".$row['NAME']."</th>";
		}
		?>
		
		
		
	</tr>
<?php
	$nbrow = UserModel::getUsersExceptManager($result);
	foreach ($result as $row) {

		echo "<tr>";
		echo "<td>".$row['ID']."</td>\n";
		echo "<td>".$row['LOGIN']."</td>\n";
		echo "<td>".$row['ROLE']."</td>\n";
		
		$nbrow2 = RightModel::getRights($row['ID'],$result2);
		foreach ($result2 as $row2) {
			?>
			<td class="center"><input id="right<?php echo $row['ID'] ?>_<?php echo $row2['BASE'] ?>"  type="checkbox" <?php if($row2['OK'] == 1){ echo "checked=\"checked\""; } ?> onClick="changeRight(<?php echo $row['ID'].", ".$row2['BASE'] ?>)"></input></td>
			<?php
		}


		echo"</tr>";
	}
		
?>
</table>

</div>


<br /><br />
